import core.App;
import core.Config;
import sun.misc.Signal;
import sun.misc.SignalHandler;

public class Main {
    public static void main(String[] args) throws Exception {
        Config config = new Config();
        config.load(args[0]);

        App app = new App(config);
        try {
            SignalHandler signalHandler = sig -> {
                switch (sig.getName()) {
                    case "INT":
                    case "TERM": {
                        try {
                            app.close();
                        } catch (Exception ignore) {
                        }
                        break;
                    }
                }
            };
            signalHandler.handle(new Signal("INT"));
            signalHandler.handle(new Signal("TERM"));
            app.run();
            System.out.println("ssk service (" + config.getRunType().getDesc() + ") started");
        } catch (Exception e) {
            System.out.println("ssk service (" + config.getRunType().getDesc() + ") stop");
            app.close();
            e.printStackTrace();
        }
    }
}